package com.demo.small_tool.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Administrator
 */
@JsonInclude
@JsonPropertyOrder({"code", "msg", "desc", "data"})
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Resp<T> implements Serializable {


    private String code = "200";
    private String msg;
    private String desc;
    private T data;

    public Resp(T data) {
        this.data = data;
    }

    public Resp(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Resp<T> success() {
        return new Resp("200", "success", "成功", null);
    }

    public static <T> Resp<T> success(T data) {
        return new Resp(data);
    }

    public static <T> Resp<T> success(String code, String msg, T data) {
        return new Resp(code, msg, data);
    }

    public static <T> Resp<T> fail(String code, String msg, String desc) {
        return new Resp<>(code, msg, desc, null);
    }
}

